#pragma once

#include <Windows.h>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>

typedef struct TreeNode {
	UINT32 data;
	TreeNode *ltree;
	TreeNode *rtree;
} _TreeNode;

typedef struct Tree {
	UINT32 count;
	TreeNode *root;
} _Tree;

class Stack {
private:
	typedef struct List {
		ULONG *pData;
		UINT32 DataSize;
		List *next;
		List *prev;
	} _List;
	List *m_Head;
	List *m_Cur;
	UINT32 m_StackSurplus;
	UINT32 m_ListCount;
	const UINT32 m_StackMaxSize;

public:
	Stack(void);
	~Stack(void);
public:
	UINT32 GetTopDataSize(void);
	BOOL StackEmpty(void);
	UINT32 Push(void *pData, UINT32 size);
	UINT32 Pop(void *pData);
};

class TreeOpt {
public:
	static TreeNode *TreeCreate(Tree *root, UINT32 deep);
	static void TreeDestory(TreeNode *top);
	static void TreeDestory(TreeNode *top, UINT32 *DelCount);
	static void TreeVist(Stack *S, TreeNode *top, void *CallBackFunc);
};
